#include <iostream>

#include <thrift/concurrency/ThreadManager.h>
#include <thrift/concurrency/PlatformThreadFactory.h>
using namespace std;
using namespace boost;
using namespace apache::thrift;
// using namespace apache::thrift::concurrency;

class TestTask : public concurrency::Runnable {
  int id_;
 public:
  TestTask(int id) : id_(id) {}
  virtual void run() {
    cout << "started " << id_ << endl;
    sleep(1);
    cout << "finished " << id_ << endl;
  }
};


int main() {
  shared_ptr<concurrency::ThreadManager> thread_manager = concurrency::ThreadManager::newSimpleThreadManager(10, 20);

  shared_ptr<concurrency::PlatformThreadFactory> factory = shared_ptr<concurrency::PlatformThreadFactory>(new concurrency::PlatformThreadFactory());
  thread_manager->threadFactory(factory);

  thread_manager->start();

  for(int i = 0; i < 100; ++i) {
    thread_manager->add(shared_ptr<concurrency::Runnable>(new TestTask(i)));
  }

  sleep(10);

  thread_manager->stop();
  return 0;
}

